﻿using MebAppMarketplace.Biz;
using MebAppMarketplace.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MebAppMarketplace.Controllers
{
    /// <summary>
    /// 实现商店应用管理功能
    /// </summary>
    [Authorize(Roles = "Admin")]
    public class AppManagementController : Controller
    {
        public AppService appService { get; set; }
        /// <summary>
        /// 首页显示商店应用列表及下列功能链接
        /// </summary>
        /// <returns></returns>
        public IActionResult Index(string kw, int page)
        {
            //功能包括 搜索，上架/下架，审核
            var list = appService.GetAuditList(kw, page);
            return View(list);
        }

        public IActionResult Versions(Guid id, int page)
        {
            var list = appService.GetVersionList(id, page);
            return View(list);
        }

        /// <summary>
        /// 审核通过
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Approve(Guid id)
        {
            appService.Approve(id);
            return this.RedirectToReturnUrl();
        }

        public IActionResult Reject(Guid id)
        {
            return View();
        }

        /// <summary>
        /// 审核拒绝
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Reject(Guid id, string reason)
        {
            appService.Reject(id, reason);
            return View();
        }

        /// <summary>
        /// 上架
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Shelve(Guid id)
        {
            return View();
        }

        public IActionResult OffShelve(Guid id)
        {
            return View();
        }

        /// <summary>
        /// 下架
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult OffShelve(Guid id, string reason)
        {
            return View();
        }
    }
}
